package org.dzms.dao;

import java.util.List;

import org.dzms.commons.DataHandler;
import org.dzms.commons.IPage;
import org.dzms.commons.PageHandler;
import org.dzms.entity.FoodClass;

public class FoodClassDAO implements IPage{
	/**
	 * 商户列表
	 */
	
	//按照人气进行降序排列
	public List<FoodClass> findSentiment(){
		String sql = "select * from foodclass order by fccommens desc";
		return DataHandler.query(sql, null, FoodClass.class);
	}
	//查询所有商户信息
	public List<FoodClass> findAllFc(){
		String sql= "select * from foodclass";
		return DataHandler.query(sql, null, FoodClass.class);
	}
	//保存商户信息
	public void saveFc(FoodClass fc){
		String sql = "insert into foodclass(fcshname,fccommens,fcavgpri,fcclass,fcaddress,"
							+ "fcdetaddress,fcrecomm,fcbulk,fcprefer,fctaste,fcenvir,fcservice,fcpic) "
									+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
		DataHandler.update(sql, new Object[]{fc.getFcshname(),fc.getFccommens(),fc.getFcavgpri(),
												fc.getFcclass(),fc.getFcaddress(),fc.getFcdetaddress(),fc.getFcrecomm(),
													fc.getFcbulk(),fc.getFcprefer(),fc.getFctaste(),fc.getFcenvir(),fc.getFcservice(),
														fc.getFcpic()});
	}
	//删除商户信息
	public void deleteFc(int fcid){
		String sql = "delete from foodclass where fcid=?";
		DataHandler.update(sql, new Object[]{fcid});
	}
	//修改商户信息
	public void updateFc(FoodClass fc){
		String sql = "update foodclass set fcshname=?,fccommens=?,fcavgpri=?,fcclass=?,"
							+ "fcaddress=?,fcdetaddress=?,fcrecomm=?,fcbulk=?,fcprefer=?,fctaste=?,"
								+ "fcenvir=?,fcservice=?,fcpic=? where pcid=?";
		DataHandler.update(sql, new Object[]{fc.getFcshname(),fc.getFccommens(),fc.getFcavgpri(),
												fc.getFcclass(),fc.getFcaddress(),fc.getFcdetaddress(),fc.getFcrecomm(),
													fc.getFcbulk(),fc.getFcprefer(),fc.getFctaste(),fc.getFcenvir(),fc.getFcservice(),
														fc.getFcpic(),fc.getFcid()});
	}
	
	//实现分页查询
	public <E> List<E> findCurrentPageData(PageHandler handler) {
		String sql = "select * from foodclass limit ?,?";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return DataHandler.query(sql, new Object[]{(handler.getCurrentPage()-1)*handler.getPageSize(),handler.getPageSize()},FoodClass.class);
	}

	public <E> List<E> findCurrentPageDatadesc(PageHandler handler) {
		String sql = "select * from foodClass  order by fccommens desc limit ?,?";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return DataHandler.query(sql, new Object[]{(handler.getCurrentPage()-1)*handler.getPageSize(),handler.getPageSize()},FoodClass.class);
	}
	public int findCountPage(PageHandler handler) {
		String sql = "select ceil(count(*)/?) from foodclass";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return Integer.parseInt(DataHandler.uniqueQuery(sql, new Object[]{handler.getPageSize()}).toString());
	}
	public <E> List<E> foods(String a, PageHandler handler) {
		String sql = "select * from foodClass where fcshname like ? limit ?,?";
//		if (handler.getCond() != null && handler.getCond().length() != 0) {
//			sql += " where " + handler.getConditonSQL();
//		}
		return DataHandler.query(sql, new Object[]{a,(handler.getCurrentPage()-1)*handler.getPageSize(),handler.getPageSize()},FoodClass.class);
	}
	
	
}
